import tkinter
import Home
import MessageInvert
import CreateExcel
import SelectEnv
import sys
sys.stdout.reconfigure(encoding='utf-8')

version = 'V0.2'
main_window = tkinter.Tk()
main_window.title('测试小工具集')
main_window.geometry('800x600')

def destory_widget_all():
    reset_grid_configure()
    for widget in main_window.winfo_children():
        if not isinstance(widget, tkinter.Menu):
            widget.destroy()

def reset_grid_configure():
    for i in range(20):
        main_window.grid_columnconfigure(i,weight=0)

def showEnv():
    destory_widget_all()
    SelectEnv.SelectEnv(main_window)

def newEnv():
    SelectEnv.NewEnv()

def newSet():
    SelectEnv.EnvSeting()

def showHome():
    destory_widget_all()
    Home.Home(main_window)

def showMessage():
    destory_widget_all()
    MessageInvert.MessageInvert(main_window)

def showExcel():
    destory_widget_all()
    CreateExcel.CreateExcel(main_window)


#菜单
main_menubar = tkinter.Menu(main_window)

filemenu = tkinter.Menu(main_window, tearoff=0)
main_menubar.add_cascade(label='功能选择', menu=filemenu)
filemenu.add_command(label='测试环境查找', command=showEnv)
filemenu.add_command(label='报文转化', command=showMessage)
filemenu.add_command(label='用例模板转换', command=showExcel)
filemenu.add_command(label='返回', command=showHome)

envSeting = tkinter.Menu(main_window, tearoff=0)
main_menubar.add_cascade(label='测试环境设置', menu=envSeting)
envSeting.add_command(label='新增环境数据', command=newEnv)
envSeting.add_command(label='环境配置', command=newSet)

main_window.config(menu=main_menubar)

if __name__ == '__main__':
    showHome()
    main_window.mainloop()
